﻿using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using ReflectionStudio.Core.Events;
namespace WPFExcelReport
{
    /// <summary>
    /// Interaction logic for EditEventWindow.xaml
    /// </summary>
    public partial class TUBTVK02
    {
        ITXEXRPT ITXEXRPT;
        public TUBTVK02()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VVKPOS();
            this.DataContext = MV;
            InitializeComponent();
            ITXEXRPT = new ITXEXRPT();
            ITXEXRPT.Root = "C:\\IntexReport";
            ITXEXRPT.strCompany = app.company;
            ITXEXRPT.PrintType = "OpenExcel";
        }

       
        public override void QueryCommand(object sender, System.Windows.RoutedEventArgs e)
        {
            dwData = TBMain.NewRow();
            dwData["VKPMANDANT"] = app.Mandant;
            if (KUNDNR == "000000")
            {
                KUNDNR = "";
            }
            if (NEUDATE.Trim() == "")
                NEUDATE = "20991231";
            if (NEUDATS.Trim() == "")
                NEUDATS = "0";
            if (DTEND.Trim() == "")
                DTEND = "20991231";
            if (DTSTART.Trim() == "")
                DTSTART = "0";
            
            dwData["VKPKUNDNR"] = " AND VKPKUNDNR LIKE '%" + KUNDNR + "%'";
            dwData["VKPPOSTYP"] = " AND VKKAUFART LIKE '%" + AUFART.Trim() + "%'";
            dwData["VKPKDKOMM"] = " AND VKPKDKOMM LIKE '%" + VKPKDKOMM + "%'";
            dwData["VKPSACHBE"] = " AND VKPSACHBE LIKE'%" + SACHBE + "%'";
            dwData["VKPFILLER2"] = " AND VKPLIEFTERM>='" + DTSTART + "' AND VKPLIEFTERM<='" + DTEND + "'";
            dwData["VKPNEUBEN"] = " AND VKPNEUDAT>='" + NEUDATS + "' AND VKPNEUDAT<='" + NEUDATE + "'";
            dwData["VKPART"] = " AND VKPART LIKE '%" + ART.Trim() + "%' ";         
            if (LFD == "000000")
            {
                LFD = "";
            }
            dwData["VKPAUFLFD"] = " AND VKPAUFKRS LIKE '%" + KRS.Trim() + "%' AND VKPAUFLFD LIKE '%" + LFD.Trim() + "%'" + " AND VKPKOLL LIKE '" + KOLL.Trim() + "%'" + " AND VKKANSPRECH LIKE '%" + VKKANSPRECH + "%' ";
            if(AUFART=="KS")
            {
                SResult = TMV.QVKP23ZY(dwData);
            }
            else
            {
                if (uncompleteCheckBox.IsChecked==true)
                {
                    SResult = TMV.QVK2301UBT(dwData);
                }
                else
                {
                    SResult = TMV.QVK23UBT(dwData);
                }
              
            } 
            MergeData(SResult, false);
            AUFART = "";
            base.QueryCommand(sender, e);
        }
        public override void PrintCommand(object sender, RoutedEventArgs e)
        {
            try
            {
                if (ITXEXRPT == null)
                {
                    ITXEXRPT = new ITXEXRPT();
                    ITXEXRPT.Root = "C:\\IntexReport";
                    ITXEXRPT.strCompany = app.company;
                    ITXEXRPT.PrintType = "OpenExcel";
                }
                ITXEXRPT.dsSource = new DataSet();
                ITXEXRPT.dsSource.Merge(MV.SetProd);
                //ITXEXRPT.dsSource.Merge(Se.Env);

                ITXEXRPT.DocType = "UBTVK02";

                ITXEXRPT.strExcelFile = @"UBT\UBTVK02.xls";
                string filename = ITXEXRPT.WriteExcelReport();
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }

        private void ZYQueryCommand(object sender, RoutedEventArgs e)
        {
            AUFART = "KS";
            QueryCommand(sender, e);
        }
    }
}
